package com.bidv.wcm;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;

import com.ibm.workplace.wcm.api.Content;
import com.ibm.workplace.wcm.api.Document;
import com.ibm.workplace.wcm.api.DocumentId;
import com.ibm.workplace.wcm.api.Identity;
import com.ibm.workplace.wcm.api.Repository;
import com.ibm.workplace.wcm.api.RichTextComponent;
import com.ibm.workplace.wcm.api.VirtualPortalContext;
import com.ibm.workplace.wcm.api.WCM_API;
import com.ibm.workplace.wcm.api.Workspace;
import com.ibm.workplace.wcm.api.query.Query;
import com.ibm.workplace.wcm.api.query.ResultIterator;
import com.ibm.workplace.wcm.api.query.Selectors;

/**
 * Servlet implementation class GetContent
 */
@WebServlet("/GetContent")
public class GetContent extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetContent() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String data = "";
		try {
			Repository repo = WCM_API.getRepository();
			VirtualPortalContext vctx = repo.generateVPContextFromContextPath(request.getParameter("Context"));
			VPContent vpA = new VPContent();
			vpA.requestID = request.getParameter("ID");
			vpA.doclib = request.getParameter("DocLib");
			WCM_API.getRepository().executeInVP(vctx, vpA);
			data = vpA.Data;
			
		} catch (Exception Ex){
			
		}
//		String s = request.getContextPath();
//		s = s.replaceAll(".TestWCM", "");
//		sb.append("<iframe height=200 width=800 frameborder=0 src='"+s+"WCMComment/index.jsp?ID="+request.getParameter("ID")+"&UserID="+UserID+"'></iframe>");
		response.setContentType("text/html;charset=utf-8");
		response.getOutputStream().write(data.getBytes("UTF-8"));
	}

}
